﻿using System;
using System.Collections.Generic;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;

namespace TaleWorlds.CampaignSystem.BarterSystem.Barterables
{
	// Token: 0x02000416 RID: 1046
	public class ItemBarterable : Barterable
	{
		// Token: 0x17000D27 RID: 3367
		// (get) Token: 0x06003F98 RID: 16280 RVA: 0x0013A010 File Offset: 0x00138210
		public override string StringID
		{
			get
			{
				return "item_barterable";
			}
		}

		// Token: 0x06003F99 RID: 16281 RVA: 0x0013A017 File Offset: 0x00138217
		public ItemBarterable(Hero ownerHero, Hero otherHero, PartyBase ownerParty, PartyBase otherParty, ItemRosterElement itemRosterElement, int averageValueOfItemInNearbySettlements) : base(ownerHero, ownerParty)
		{
			this._itemElement = itemRosterElement;
			this._averageValueOfItemInNearbySettlements = averageValueOfItemInNearbySettlements;
			this._otherParty = otherParty;
			this._otherHero = otherHero;
		}

		// Token: 0x17000D28 RID: 3368
		// (get) Token: 0x06003F9A RID: 16282 RVA: 0x0013A040 File Offset: 0x00138240
		public ItemRosterElement ItemRosterElement
		{
			get
			{
				return this._itemElement;
			}
		}

		// Token: 0x17000D29 RID: 3369
		// (get) Token: 0x06003F9B RID: 16283 RVA: 0x0013A048 File Offset: 0x00138248
		public override int MaxAmount
		{
			get
			{
				return this._itemElement.Amount;
			}
		}

		// Token: 0x17000D2A RID: 3370
		// (get) Token: 0x06003F9C RID: 16284 RVA: 0x0013A064 File Offset: 0x00138264
		public override TextObject Name
		{
			get
			{
				return this._itemElement.EquipmentElement.Item.Name;
			}
		}

		// Token: 0x17000D2B RID: 3371
		// (get) Token: 0x06003F9D RID: 16285 RVA: 0x0013A08C File Offset: 0x0013828C
		public int ItemValue
		{
			get
			{
				return this._averageValueOfItemInNearbySettlements;
			}
		}

		// Token: 0x06003F9E RID: 16286 RVA: 0x0013A094 File Offset: 0x00138294
		public override int GetUnitValueForFaction(IFaction faction)
		{
			return MathF.Round(Campaign.Current.Models.BarterModel.GetBarterPenalty(faction, this, this._otherHero, this._otherParty).ResultNumber * (float)this.ItemValue);
		}

		// Token: 0x06003F9F RID: 16287 RVA: 0x0013A0D8 File Offset: 0x001382D8
		public override void CheckBarterLink(Barterable parentLinkedBarterable)
		{
		}

		// Token: 0x06003FA0 RID: 16288 RVA: 0x0013A0DC File Offset: 0x001382DC
		public override ImageIdentifier GetVisualIdentifier()
		{
			return new ImageIdentifier(this._itemElement.EquipmentElement.Item, "");
		}

		// Token: 0x06003FA1 RID: 16289 RVA: 0x0013A109 File Offset: 0x00138309
		public override string GetEncyclopediaLink()
		{
			return "";
		}

		// Token: 0x06003FA2 RID: 16290 RVA: 0x0013A110 File Offset: 0x00138310
		public override void Apply()
		{
			if (this._otherParty != null)
			{
				base.OriginalParty.ItemRoster.AddToCounts(this._itemElement.EquipmentElement, -base.CurrentAmount);
				this._otherParty.ItemRoster.AddToCounts(this._itemElement.EquipmentElement, base.CurrentAmount);
				return;
			}
			ItemRosterElement itemRosterElement = new ItemRosterElement(this._itemElement.EquipmentElement, base.CurrentAmount);
			GiveItemAction.ApplyForHeroes(base.OriginalOwner, this._otherHero, itemRosterElement);
		}

		// Token: 0x06003FA3 RID: 16291 RVA: 0x0013A19F File Offset: 0x0013839F
		internal static void AutoGeneratedStaticCollectObjectsItemBarterable(object o, List<object> collectedObjects)
		{
			((ItemBarterable)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x06003FA4 RID: 16292 RVA: 0x0013A1AD File Offset: 0x001383AD
		protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
		{
			base.AutoGeneratedInstanceCollectObjects(collectedObjects);
		}

		// Token: 0x04001298 RID: 4760
		private readonly ItemRosterElement _itemElement;

		// Token: 0x04001299 RID: 4761
		private readonly Hero _otherHero;

		// Token: 0x0400129A RID: 4762
		private readonly PartyBase _otherParty;

		// Token: 0x0400129B RID: 4763
		private readonly int _averageValueOfItemInNearbySettlements;
	}
}
